<?php
class UcenterAction extends BaseAction
{

    public function index()
    {
        if (empty($_SESSION['userinfo']))
        {
            $this->assign("jumpUrl", "__APP__");
            $this->assign("waitSecond", 2);
            $this->error("请先登录");
        }
        $result = M("vip")->where("v_id = {$_SESSION['userinfo']['v_id']}")->find();
        $this->assign('data', $result);
        $this->display();
    }

    public function update()
    {
        if (empty($_SESSION['userinfo']))
        {
            $this->assign("jumpUrl", "__APP__");
            $this->assign("waitSecond", 2);
            $this->error("请先登录");
        }
        if ($_POST)
        {
            $data = array();
            $data['v_name'] = filter_str($_POST['name']);
            $data['v_email'] = filter_str($_POST['email']);
            $data['v_tel'] = filter_str($_POST['phone']);
            $data['v_idcardno'] = filter_str($_POST['idnum']);
            $data['sheng'] = filter_str($_POST['city']);
            $data['shi'] = filter_str($_POST['district']);
            $rs = M('vip')->data($data)->where("v_id = {$_SESSION['userinfo']['v_id']}")->save();
            if ($rs)
            {
                $this->assign("jumpUrl", "__URL__");
                $this->assign("waitSecond", 3);
                $this->success("修改成功！！！");
            }
            else
            {
                $this->assign("jumpUrl", "__URL__/update");
                $this->assign("waitSecond", 3);
                $this->error("修改失败！！！");
            }
        }
        else
        {
            $result = M("vip")->where("v_id = {$_SESSION['userinfo']['v_id']}")->find();
            $this->assign('data', $result);
            $this->display('update');
        }
    }

    public function manage()
    {
        if (empty($_SESSION['userinfo']))
        {
            $this->assign("jumpUrl", "__APP__");
            $this->assign("waitSecond", 2);
            $this->error("请先登录");
        }
        $array = array(
            1, 
            2, 
            3, 
            4, 
            5, 
            6
        );
        if (isset($_GET['t']) && in_array($_GET['t'], $array))
        {
            $t = trim($_GET['t']);
            if ($_GET['t'] == 1)
            {
                $pre = 'b_';
                $mod = M('bieshu');
            }
            if ($_GET['t'] == 2)
            {
                $pre = 'x_';
                $mod = M('xiezilou');
            }
            if ($_GET['t'] == 3)
            {
                $pre = 's_';
                $mod = M('shangpu');
            }
            if ($_GET['t'] == 4)
            {
                $pre = 'g_';
                $mod = M('gongyu');
            }
            if ($_GET['t'] == 5)
            {
                $pre = 'z_';
                $mod = M('zheng');
            }
            if ($_GET['t'] == 6)
            {
                $pre = 'y_';
                $mod = M('yezhu');
            }
            $rs = $mod->where("{$pre}broker = {$_SESSION['userinfo']['v_id']}")->select();
            $this->assign('result', $rs);
            $this->assign('p', $_GET['t']);
            $this->display('manage');
        }
        else
        {
            $_SESSION['userinfo']['v_id'] = 32;
            $shangpu = M('shangpu')->where("s_broker = '{$_SESSION['userinfo']['v_id']}'")->select();
            $this->display('manage');
        }
    }

    function updatehouse()
    {
        if (empty($_SESSION['userinfo']))
        {
            $this->assign("jumpUrl", "__APP__");
            $this->assign("waitSecond", 2);
            $this->error("请先登录");
        }
        $array = array(
            1, 
            2, 
            3, 
            4, 
            5, 
            6
        );
        if (isset($_GET['t']) && in_array($_GET['t'], $array))
        {
            $t = trim($_GET['t']);
            if ($_GET['t'] == 1)
            {
                $pre = 'b_';
                $mod = M('bieshu');
            }
            if ($_GET['t'] == 2)
            {
                $pre = 'x_';
                $mod = M('xiezilou');
            }
            if ($_GET['t'] == 3)
            {
                $pre = 's_';
                $mod = M('shangpu');
            }
            if ($_GET['t'] == 4)
            {
                $pre = 'g_';
                $mod = M('gongyu');
            }
            if ($_GET['t'] == 5)
            {
                $pre = 'z_';
                $mod = M('zheng');
            }
            if ($_GET['t'] == 6)
            {
                $pre = 'y_';
                $mod = M('yezhu');
            }
            $id = trim($_GET['id']);
            $rs = $mod->where("{$pre}id = {$id}")->delete();
            if($rs)
            {
            	exit('success');
            }
            else
            {
            	exit('fail');
            }
        }
    }
}
?>
